package com.sara.util;

import org.apache.commons.dbcp2.BasicDataSource;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;

public class ConectionManager {
    private static BasicDataSource dataSource = new BasicDataSource();
    private static String DRIVER;
    private static String URL;
    private static String USERNAME;
    private static String PASSWORD;

    static {
        try{
            Properties properties = new Properties();
            //TODO.....
            properties.load(ConectionManager.class.getClassLoader().getResourceAsStream("Config.properties"));
            DRIVER = properties.getProperty("jdbc.driver");
            URL = properties.getProperty("jdbc.url");
            USERNAME = properties.getProperty("jdbc.username");
            PASSWORD = properties.getProperty("jdbc.password");
        }catch(IOException e){
            e.printStackTrace();
        }
        dataSource.setDriverClassName(DRIVER);
        dataSource.setUrl(URL);
        dataSource.setUsername(USERNAME);
        dataSource.setPassword(PASSWORD);

        dataSource.setInitialSize(2);
        dataSource.setMaxIdle(5);
        dataSource.setMinIdle(1);
        dataSource.setMaxWaitMillis(5000);
    }
    public static DataSource getConection() {
        return dataSource;
    }

}
